package utils;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;

public class Logger {
    private BufferedWriter writer;
    
    public Logger(String logFile, boolean append) {
        try {
            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logFile, append), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    
    public void info(String message, boolean isConsole) {
        try {
            writer.write(message + "\n");
            if (isConsole) {
                System.out.println(message);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public void flush() {
        try {
            writer.flush();
        } catch (IOException e) {
        }
    }
    
    
    public void close() {
        try {
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
